package org.apache.solr.handler.dataimport.scheduler;

import java.util.Timer;

/**
 * 定期优化索引
 * @author ZHANGJIE116
 *
 */
public class OptimizedIndexHTTPPostScheduler extends BaseTimerTask {

	public OptimizedIndexHTTPPostScheduler(String webAppName, Timer t)
			throws Exception {
		super(webAppName, t, SolrDataImportProperties.OPTIMIZED_INDEX);
		logger.info("<index optimized process> OptimizedIndexHTTPPostScheduler init");
	}
	
	@Override
	public void run() {
		try {
			if (server.isEmpty() || webapp.isEmpty()
					|| params == null
					|| params.isEmpty()) {
				logger.warn("<index optimized process> Insuficient info provided for data, OptimizedIndexParams is null");
				logger.info("<index optimized process> Reloading global dataimport.properties");
				reloadParams();
			} else if (coresArr.length == 0
					|| (coresArr.length == 1 && coresArr[0].isEmpty())) {
				logger.warn("<index optimized process> No cores scheduled for data import");
				logger.info("<index optimized process> Reloading global dataimport.properties");
				reloadParams();
			} else {
				for (String core : coresArr) {
					prepUrlSendHttpPost(SolrDataImportProperties.OPTIMIZED_INDEX, core, params);
				}
			}
		} catch (Exception e) {
			logger.error("Failed to prepare for sendHttpPost", e);
			reloadParams();
		}		
	}

}
